package wenjie.chen.receiver.commandHandler.impl;

import lombok.NonNull;
import lombok.RequiredArgsConstructor;
import lombok.extern.log4j.Log4j;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;
import wenjie.chen.receiver.command.DecreaseAmountCommand;
import wenjie.chen.receiver.command.IncreaseAmountCommand;
import wenjie.chen.receiver.commandHandler.IAccountCommandHandler;
import wenjie.chen.receiver.dao.AccountDao;

@Log4j
@Component("accountCommandHandlerCancel")
@Transactional
@RequiredArgsConstructor
public class AccountCommandHandlerCancel implements IAccountCommandHandler {
    @NonNull
    private final AccountDao accountDao;

    @Override
    public void increaseAmount(IncreaseAmountCommand command) {
        accountDao.cancelIncreaseAmount(command.getAccountId(), command.getAmount());
    }

    @Override
    public void decreaseAmount(DecreaseAmountCommand command) {
        accountDao.cancelDecreaseAmount(command.getAccountId(), command.getAmount());
    }
}
